<template>
	<view class="zone">
		<Header title="我的潮玩卡" color="#fff"></Header>
		<view class="main">
			<view class="item">
				<view>	
					<p>累计获得(张)</p>
					<h3>{{userinfo.cards}}</h3>
				</view>
				<image src="http://img.cpgm.cc/panda/static/self/card2.png" mode="widthFix" />
			</view>

			<view class="box2" v-for="item,index in listdata" :key="index">
				<view class="flex">
					<view >
						<view class="lname" >
							{{item.remark}}
						</view>	
						<view class="ltime">
							{{item.created_at}}
						</view>
					</view>
					<view class="lshul">
						{{item.operation_type == 1?'+':'-'}}{{item.number}}
					</view>
				</view>
			</view>

			<view class="empty" v-if="listdata == ''">
				<image src="http://img.cpgm.cc/wkxxz/static/public/empty.png" mode="widthFix" />
				<text>数据为空</text>
			</view>
			<u-loadmore v-else :status="status" :icon-type="iconType" :load-text="loadText" />
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				listdata:[],
				page:1,
				max_page:1,
				status: 'loadmore',
				iconType: 'flower',
				loadText: {
					loadmore: '轻轻上拉',
					loading: '努力加载中',
					nomore: '没有更多了'
				},
				userinfo: uni.getStorageSync('userinfo'),
			};
		},
		onLoad(){
			this.getUserInfo();
			this.getCrystalList();
		},
		onReachBottom() {
			if (this.page >= this.max_page){
					this.status = 'nomore' 
					return;
				} 
				this.status = 'loading';
				this.page = ++this.page;
				this.getCrystalList()
				setTimeout(() => {
					if (this.page > this.max_page || this.page == this.max_page) this.status = 'nomore';
					else this.status = 'loading';
				}, 500)
		},
		methods: {
			// 请求用户信息接口
			async getUserInfo() {
				this.$getUserInfo.getUserInfo((res) => {
					this.userinfo = res.data
				})
			},

			async getCrystalList(){
				let res = await this.$http.index.getCardList({
					page:this.page
				})
				this.list = res.data
				this.max_page = res.page
				this.listdata = [...this.listdata , ...this.list]
				if (this.page > this.max_page || this.page == this.max_page) this.status = 'nomore';
			},
		},
	}
</script>

<style lang="less">
.zone {
	background: #201D24;
	min-height: 100vh;
}

.main {
	padding: 10px;

	.item {
		background: linear-gradient(90deg, #4F4D4C 0%, #262626 100%);
		box-shadow: 0px 4px 4px 0px rgba(0,0,0,0.5), inset 0px 7px 9px 0px rgba(82,82,82,0.5), inset 0px -7px 9px 0px rgba(95,95,95,0.5), inset 7px 0px 9px 0px rgba(112,112,112,0.5), inset -7px 0px 9px 0px rgba(112,112,112,0.5);
		border-radius: 9px;
		padding: 30px 20px;
		position: relative;
		display: flex;
		align-items: center;
		justify-content: space-between;

		p {
			color: #FFFFFF;
			font-size: 12px;
		}

		h3 {
			color: #fff;
			font-size: 32px;
			font-weight: 600;
			margin-top: 15px;
		}

		image {
			position: absolute;
			right: 10px;
			width: 140px;
			top: -50%;
		}
	}
}

.flex {
	display: flex;
	align-items: center;
	justify-content: space-between;
}



.box2 {
		width: 100%;
		background: linear-gradient(272deg, #3D3C40 0%, #353339 100%);
		border-radius: 11rpx;
		box-sizing: border-box;
		padding: 10px;
		margin-top: 10px;
	}
	.lname {
		font-size: 14px;
		font-weight: 600;
		color: #FFFFFF;
	}
	.ltime {
		font-size: 12px;
		font-weight: 400;
		color: #c0c0c1;
		margin-top: 10rpx;
	}
	.lshul {
		font-size: 16px;
		font-weight: bold;
		color: #FFFFFF;
	}


// 数据为空
	.empty {
		width: 100%;
		padding: 10vh 10px 10px;
		display: flex;
		align-items: center;
		flex-direction: column;
		justify-content: center;

		image {
			width: 60%;
		}
		text {
			// color: #131314;
			font-weight: 600;
		}
	}
</style>
